<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of v_overlapadd</title>
  <meta name="keywords" content="v_overlapadd">
  <meta name="description" content="V_OVERLAPADD join overlapping frames together X=(F,WIN,INC)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">v_mfiles</a> &gt; v_overlapadd.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for v_mfiles&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>v_overlapadd
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>V_OVERLAPADD join overlapping frames together X=(F,WIN,INC)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [x,zo]=v_overlapadd(f,win,inc) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment">V_OVERLAPADD join overlapping frames together X=(F,WIN,INC)

 Usage for frequency-domain processing:
       S=...;                              % input signal
       OV=2;                               % overlap factor of 2 (4 is also often used)
       INC=20;                             % set frame increment in samples
       NW=INC*OV;                          % DFT window length
       W=sqrt(hamming(NW,'periodic'));     % omit sqrt if OV=4
       W=W/sqrt(sum(W(1:INC:NW).^2));      % normalize window
       F=v_rfft(v_enframe(S,W,INC),NW,2);      % do STFT: one row per time frame, +ve frequencies only
       ... process frames ...
       X=v_overlapadd(v_irfft(F,NW,2),W,INC);  % reconstitute the time waveform (omit &quot;X=&quot; to plot waveform)

 Inputs:  F(NR,NW) contains the frames to be added together, one
                   frame per row.
          WIN(NW)  contains a window function to multiply each frame.
                   WIN may be omitted to use a default rectangular window
                   If processing the input in chunks, WIN should be replaced by
                   ZI on the second and subsequent calls where ZI is the saved
                   output state from the previous call.
          INC      gives the time increment (in samples) between
                   succesive frames [default = NW].

 Outputs: X(N,1) is the output signal. The number of output samples is N=NW+(NR-1)*INC.   
          ZO     Contains the saved state to allow a long signal
                 to be processed in chunks. In this case X will contain only N=NR*INC
                 output samples.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [x,zo]=v_overlapadd(f,win,inc)</a>
0002 <span class="comment">%V_OVERLAPADD join overlapping frames together X=(F,WIN,INC)</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% Usage for frequency-domain processing:</span>
0005 <span class="comment">%       S=...;                              % input signal</span>
0006 <span class="comment">%       OV=2;                               % overlap factor of 2 (4 is also often used)</span>
0007 <span class="comment">%       INC=20;                             % set frame increment in samples</span>
0008 <span class="comment">%       NW=INC*OV;                          % DFT window length</span>
0009 <span class="comment">%       W=sqrt(hamming(NW,'periodic'));     % omit sqrt if OV=4</span>
0010 <span class="comment">%       W=W/sqrt(sum(W(1:INC:NW).^2));      % normalize window</span>
0011 <span class="comment">%       F=v_rfft(v_enframe(S,W,INC),NW,2);      % do STFT: one row per time frame, +ve frequencies only</span>
0012 <span class="comment">%       ... process frames ...</span>
0013 <span class="comment">%       X=v_overlapadd(v_irfft(F,NW,2),W,INC);  % reconstitute the time waveform (omit &quot;X=&quot; to plot waveform)</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% Inputs:  F(NR,NW) contains the frames to be added together, one</span>
0016 <span class="comment">%                   frame per row.</span>
0017 <span class="comment">%          WIN(NW)  contains a window function to multiply each frame.</span>
0018 <span class="comment">%                   WIN may be omitted to use a default rectangular window</span>
0019 <span class="comment">%                   If processing the input in chunks, WIN should be replaced by</span>
0020 <span class="comment">%                   ZI on the second and subsequent calls where ZI is the saved</span>
0021 <span class="comment">%                   output state from the previous call.</span>
0022 <span class="comment">%          INC      gives the time increment (in samples) between</span>
0023 <span class="comment">%                   succesive frames [default = NW].</span>
0024 <span class="comment">%</span>
0025 <span class="comment">% Outputs: X(N,1) is the output signal. The number of output samples is N=NW+(NR-1)*INC.</span>
0026 <span class="comment">%          ZO     Contains the saved state to allow a long signal</span>
0027 <span class="comment">%                 to be processed in chunks. In this case X will contain only N=NR*INC</span>
0028 <span class="comment">%                 output samples.</span>
0029 <span class="comment">%</span>
0030 
0031 <span class="comment">%       Copyright (C) Mike Brookes 2009</span>
0032 <span class="comment">%      Version: $Id: v_overlapadd.m 10865 2018-09-21 17:22:45Z dmb $</span>
0033 <span class="comment">%</span>
0034 <span class="comment">%   VOICEBOX is a MATLAB toolbox for speech processing.</span>
0035 <span class="comment">%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html</span>
0036 <span class="comment">%</span>
0037 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0038 <span class="comment">%   This program is free software; you can redistribute it and/or modify</span>
0039 <span class="comment">%   it under the terms of the GNU General Public License as published by</span>
0040 <span class="comment">%   the Free Software Foundation; either version 2 of the License, or</span>
0041 <span class="comment">%   (at your option) any later version.</span>
0042 <span class="comment">%</span>
0043 <span class="comment">%   This program is distributed in the hope that it will be useful,</span>
0044 <span class="comment">%   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
0045 <span class="comment">%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
0046 <span class="comment">%   GNU General Public License for more details.</span>
0047 <span class="comment">%</span>
0048 <span class="comment">%   You can obtain a copy of the GNU General Public License from</span>
0049 <span class="comment">%   http://www.gnu.org/copyleft/gpl.html or by writing to</span>
0050 <span class="comment">%   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.</span>
0051 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span>
0052 [nr,nf]=size(f);            <span class="comment">% number of frames and frame length</span>
0053 <span class="keyword">if</span> nargin&lt;2
0054     win=nf;                 <span class="comment">% default increment</span>
0055 <span class="keyword">end</span>
0056 <span class="keyword">if</span> isstruct(win)
0057     w=win.w;
0058     <span class="keyword">if</span> ~numel(w) &amp;&amp; length(w)~=nf
0059         error(<span class="string">'window length does not match frames size'</span>);
0060     <span class="keyword">end</span>
0061     inc=win.inc;
0062     xx=win.xx;
0063 <span class="keyword">else</span>
0064     <span class="keyword">if</span> nargin&lt;3
0065         inc=nf;
0066     <span class="keyword">end</span>
0067     <span class="keyword">if</span> numel(win)==1 &amp;&amp; win==fix(win) &amp;&amp; nargin&lt;3       <span class="comment">% win has been omitted</span>
0068         inc=win;
0069         w=[];
0070     <span class="keyword">else</span>
0071         w=win(:).';
0072         <span class="keyword">if</span> length(w)~=nf
0073             error(<span class="string">'window length does not match frames size'</span>);
0074         <span class="keyword">end</span>
0075         <span class="keyword">if</span> all(w==1)
0076             w=[];
0077         <span class="keyword">end</span>
0078     <span class="keyword">end</span>
0079     xx=[];      <span class="comment">% partial output from previous call is null</span>
0080 <span class="keyword">end</span>
0081 nb=ceil(nf/inc);        <span class="comment">% number of overlap buffers</span>
0082 no=nf+(nr-1)*inc;       <span class="comment">% buffer length</span>
0083 z=zeros(no,nb);                      <span class="comment">% space for overlapped output speech</span>
0084 <span class="keyword">if</span> numel(w)
0085     z(repmat(1:nf,nr,1)+repmat((0:nr-1)'*inc+rem((0:nr-1)',nb)*no,1,nf))=f.*repmat(w,nr,1);
0086 <span class="keyword">else</span>
0087     z(repmat(1:nf,nr,1)+repmat((0:nr-1)'*inc+rem((0:nr-1)',nb)*no,1,nf))=f;
0088 <span class="keyword">end</span>
0089 x=sum(z,2);
0090 <span class="keyword">if</span> ~isempty(xx)
0091     x(1:length(xx))=x(1:length(xx))+xx;     <span class="comment">% add on leftovers from previous call</span>
0092 <span class="keyword">end</span>
0093 <span class="keyword">if</span> nargout&gt;1            <span class="comment">% check if we want to preserve the state</span>
0094     mo=inc*nr;          <span class="comment">% completed output samples</span>
0095     <span class="keyword">if</span> no&lt;mo
0096         x(mo,1)=0;
0097         zo.xx=[];
0098     <span class="keyword">else</span>
0099         zo.xx=x(mo+1:end);
0100         zo.w=w;
0101         zo.inc=inc;
0102         x=x(1:mo);
0103     <span class="keyword">end</span>
0104 <span class="keyword">elseif</span> ~nargout
0105     <span class="keyword">if</span> isempty(xx)
0106         k1=nf-inc;  <span class="comment">% dubious samples at start</span>
0107     <span class="keyword">else</span>
0108         k1=0;
0109     <span class="keyword">end</span>
0110     k2=nf-inc;      <span class="comment">% dubious samples at end</span>
0111     plot(1+(0:nr-1)*inc,x(1+(0:nr-1)*inc),<span class="string">'&gt;r'</span>,nf+(0:nr-1)*inc,x(nf+(0:nr-1)*inc),<span class="string">'&lt;r'</span>, <span class="keyword">...</span>
0112         1:k1+1,x(1:k1+1),<span class="string">':b'</span>,k1+1:no-k2,x(k1+1:end-k2),<span class="string">'-b'</span>,no-k2:no,x(no-k2:no),<span class="string">':b'</span>);
0113     xlabel(<span class="string">'Sample Number'</span>);
0114     title(sprintf(<span class="string">'%d frames of %d samples with %.0f%% overlap = %d samples'</span>,nr,nf,100*(1-inc/nf),no));
0115 <span class="keyword">end</span></pre></div>
<hr><address>Generated by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>